using System;
using System.Collections.Generic;
using UnityEngine;


public class MousePoint : MonoBehaviour
{
    public static Vector3 MousePosition;

    private Camera Camera;

    private int layerFloor;
    private int layerCharacter;
    private int layerGrid;

    public static  Pawn CurrentPawn;
    public static CardPosition CurrentCardPosition;

    public Status status;

    public static bool ifDraging;


    /// <summary>
    /// Awake is called when the script instance is being loaded.
    /// </summary>
    void Awake()
    {
        Camera = Camera.main;
        layerFloor = LayerMask.GetMask("Floor");
        layerCharacter = LayerMask.GetMask("Character");
        layerGrid = LayerMask.GetMask("Grid");
    }


    /// <summary>
    /// Update is called every frame, if the MonoBehaviour is enabled.
    /// </summary>
    void Update()
    {
        Ray ray = Camera.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out var hit, 100f, layerFloor))
        {
            MousePosition = hit.point;
        }
        if (Physics.Raycast(ray, out var hit2, 100f, layerCharacter))
        {
            CurrentPawn = hit2.transform.parent.GetComponent<Pawn>();
        }
        else
        {
            CurrentPawn = null;
        }
        if (Physics.Raycast(ray, out var hit3, 100f, layerGrid))
        {
            CurrentCardPosition = hit3.transform.GetComponent<CardPosition>();
        }
        else
        {
            CurrentCardPosition = null;
        }

        status.ShowStatus(CurrentPawn,ifDraging);
    }
}
